package com.babyqiao.wallpaper.manager.controller;


import com.babyqiao.wallpaper.common.UnifyResult;
import com.babyqiao.wallpaper.manager.controller.dto.ActorFullInfo;
import com.babyqiao.wallpaper.manager.controller.dto.ActorQuery;
import com.babyqiao.wallpaper.manager.entity.vo.ActorResVO;
import com.babyqiao.wallpaper.manager.service.IActorInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author QLZ
 * @since 2021-02-09
 */
@RestController
@RequestMapping("/api/admin/actors")
@Api(tags = "演员信息相关接口")
public class ActorInfoController {
    @Autowired
    IActorInfoService actorInfoService;


    @PostMapping("actor")
    @ApiOperation(value = "添加演员信息", httpMethod = "POST")
    public UnifyResult setActor(@RequestBody ActorFullInfo actorFullInfo){
        return actorInfoService.setActorService(actorFullInfo)?UnifyResult.success():UnifyResult.error();

    }

    @DeleteMapping("actor/{id}")
    @ApiOperation(value = "删除演员",httpMethod = "DELETE")
    public UnifyResult deleteActor(@ApiParam(name = "id", value = "演员ID", required = true)@PathVariable String id){
        return actorInfoService.deleteActorService(id)?UnifyResult.success():UnifyResult.error();
    }

    @PutMapping("actor")
    @ApiOperation(value = "修改演员信息",httpMethod = "PUT")
    public UnifyResult updateActor(@RequestBody ActorFullInfo actorFullInfo){
        return actorInfoService.updateActorService(actorFullInfo)?UnifyResult.success():UnifyResult.error();

    }

    @PostMapping("actors/{current}/{limit}")
    @ApiOperation(value = "带条件分页查询演员信息",httpMethod = "POST")
    public UnifyResult getActors(@ApiParam(name = "current", value = "当前页码", required = true) @PathVariable long current,
                                 @ApiParam(name = "limit", value = "每页查询条数", required = true) @PathVariable long limit, @RequestBody(required = false) ActorQuery actorQuery){
        Page<ActorResVO> page=new Page<>(current,limit);
        Page<ActorResVO> actorResVoPage = actorInfoService.multipleTablesAndCondition(page, actorQuery);
        long total=actorResVoPage.getTotal();
        List<ActorResVO> records = actorResVoPage.getRecords();

        return UnifyResult.success().data("result",records).data("total",total);

    }
    @GetMapping("actor/{id}")
    @ApiOperation(value = "根据ID查演员信息",httpMethod = "GET")
    public UnifyResult getActor(@ApiParam(name="id",value = "演员ID",required = true) @PathVariable String id){
        ActorResVO actorResVO=actorInfoService.getActorByIdService(id);

        return UnifyResult.success().data("result",actorResVO);
    }

    @GetMapping("actors")
    @ApiOperation(value = "查询所有演员",httpMethod = "GET")
    public UnifyResult getActors(){
       List<ActorResVO>  actorResVO=actorInfoService.getActorsService();
        return UnifyResult.success().data("result",actorResVO);
    }



}
